package com.xique.door.bean.validation;

import cn.hutool.core.util.PhoneUtil;
import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.bean.domain.BuildHouse;
import com.xique.door.service.IBuildHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: caogq
 * @Date: 2021/9/15 08:55
 * @Description:
 */
@Component
public class HouseValidation {
    @Autowired
    private IBuildHouseService buildHouseService;

    public AjaxResult addHouseValidation(BuildHouse house){

        if (StringUtils.isEmpty(house.getHouseCode()) ||  !StringUtils.isNumeric(house.getHouseCode()) || house.getHouseCode().length()!=4) {
            return AjaxResult.error("请输入4位房屋编号");
        }

        if (StringUtils.isEmpty(house.getHouseName())) {
            return AjaxResult.error("请输入房屋名称");
        }

        if (house.getBuildingId() == null) {
            return AjaxResult.error("楼栋不能为空!");
        }

//        if (house.getFloor() == null ||  String.valueOf(house.getFloor()).length()!=2) {
//            return AjaxResult.error("请输入正确的楼层");
//        }

        BuildHouse search = new BuildHouse();
        search.setHouseCode(house.getHouseCode());
        search.setParkId(house.getParkId());
        search.setBuildingId(house.getBuildingId());
        List<BuildHouse> buildHouses = buildHouseService.selectBuildHouseList(search);
        if (!buildHouses.isEmpty()){
            return AjaxResult.error("房屋编号重复!");
        }
        return AjaxResult.success();
    }
}
